﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Shop.Core.Share;
using Shop.IServices;
using Shop.Model.Dto.Home;
using Shop.Model.Entity.System;
using Shop.Model.View.Common;
using Shop.Model.View.Home;

namespace Shop.WebApi.Controllers;

/// <summary>
/// 首页服务
/// </summary>
[ApiController]
[Route("Api/[controller]")]
public class HomeController: ShopControllerBase
{
    private readonly IHomeService _homeService;

    private readonly IAliyunAppService _AliyunAppService;

    /// <summary>
    /// 
    /// </summary>
    /// <param name="homeService"></param>
    public HomeController(IHomeService homeService
        , IAliyunAppService AliyunAppService)
    {
        _homeService = homeService;
        _AliyunAppService = AliyunAppService;
    }

    /// <summary>
    /// Banner
    /// </summary>
    /// <returns></returns>
    [HttpGet]
    [Route("Banner")]
    public AppResult<List<SysBanner>> Banner([FromQuery]BannerDto dto)
        => _homeService.Banner(dto);

    /// <summary>
    /// 获取小程序码
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost("WxaCode")]
    public async Task<AppResult<string>> GetWxaCode(WxaCodeDto input)
        => await _homeService.GetWxaCode(input);

    /// <summary>
    /// 获取分享路径
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpGet("SharePath")]
    [AllowAnonymous]
    public async Task<AppResult<string>> GetSharePath([FromQuery]SimpleDto<long> input)
        => await _homeService.GetSharePath(input.Value);

    /// <summary>
    /// 地址库
    /// </summary>
    /// <returns></returns>
    [HttpGet("AreaList")]
    public AppResult<List<AreaListVo>> AreaList([FromQuery] string dto)
        => _homeService.AreaList(dto);

    /// <summary>
    /// 获取Oss文件上传签名
    /// </summary>
    /// <param name="dir"></param>
    /// <returns></returns>
    [HttpGet("OssSign")]
    public AppResult<OssSignDto> GetOssSign()
        =>_AliyunAppService.GetOssSign(string.Empty);
}